package com.ruoyi.web.controller.jjm;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjm.domain.UserReceive;
import com.ruoyi.jjm.service.IUserReceiveService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 村民收煤记录Controller
 * 
 * @author tsr
 * @date 2020-07-15
 */
@Controller
@RequestMapping("/jjm/receive")
public class UserReceiveController extends BaseController
{
    private String prefix = "jjm/receive";

    @Autowired
    private IUserReceiveService userReceiveService;

    @RequiresPermissions("jjm:receive:view")
    @GetMapping()
    public String receive()
    {
        return prefix + "/receive";
    }

    /**
     * 查询村民收煤记录列表
     */
    @RequiresPermissions("jjm:receive:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserReceive userReceive)
    {
        startPage();
        List<UserReceive> list = userReceiveService.selectUserReceiveList(userReceive);
        return getDataTable(list);
    }

    /**
     * 导出村民收煤记录列表
     */
    @RequiresPermissions("jjm:receive:export")
    @Log(title = "村民收煤记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserReceive userReceive)
    {
        List<UserReceive> list = userReceiveService.selectUserReceiveList(userReceive);
        ExcelUtil<UserReceive> util = new ExcelUtil<UserReceive>(UserReceive.class);
        return util.exportExcel(list, "receive");
    }

    /**
     * 新增村民收煤记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存村民收煤记录
     */
    @RequiresPermissions("jjm:receive:add")
    @Log(title = "村民收煤记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserReceive userReceive)
    {
        return toAjax(userReceiveService.insertUserReceive(userReceive));
    }

    /**
     * 修改村民收煤记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserReceive userReceive = userReceiveService.selectUserReceiveById(id);
        mmap.put("userReceive", userReceive);
        return prefix + "/edit";
    }

    /**
     * 修改保存村民收煤记录
     */
    @RequiresPermissions("jjm:receive:edit")
    @Log(title = "村民收煤记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserReceive userReceive)
    {
        return toAjax(userReceiveService.updateUserReceive(userReceive));
    }

    /**
     * 删除村民收煤记录
     */
    @RequiresPermissions("jjm:receive:remove")
    @Log(title = "村民收煤记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userReceiveService.deleteUserReceiveByIds(ids));
    }
}
